package com.weilai.controller.system;

import com.weilai.bean.dto.LoginDto;
import com.weilai.controller.base.BaseController;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: demo
 * @description: 登陆注册相关控制器
 * @author: chenman
 * @create: 2018-08-09 13:16
 */
@RestController
public class LoginController extends BaseController {

    /** 
      * 用户登陆
      * @param loginDto
      * @Author: chenman
      * @Date: 2018/8/9 13:23
      */ 
    public String login(@RequestBody LoginDto loginDto) {
        UsernamePasswordToken token = new UsernamePasswordToken(loginDto.getUserName(), loginDto.getPassword()
                , loginDto.getRememberMe() == "1" ? true : false);
        Subject subject = SecurityUtils.getSubject();
        try {
            subject.login(token);
            return "";
        }
        catch (AuthenticationException e) {
            String msg = "用户或密码错误";
//            if (StringUtils.isNotEmpty(e.getMessage())) {
//                msg = e.getMessage();
//            }
            return "";
        }
    }
}
